package com.hp.TrimClient;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

public class TrimResponseHandler implements ResponseHandler<String> {

	@Override
	public String handleResponse(HttpResponse response)
			throws ClientProtocolException, IOException {

		int statusCode = response.getStatusLine().getStatusCode();
		
		HttpEntity entity = response.getEntity();
		String responseBody = "";
		
        if (entity != null) {
        	responseBody = EntityUtils.toString(entity);           
            
        }
	
		if (statusCode == 200) {
			return responseBody;
		} else {
			
			TrimJson trimJson = new TrimJson();
			throw trimJson.makeHttpEx(responseBody);
		}
	}

}
